﻿Imports System.Windows
Imports System.Threading

Public Class DBRepairWizard

    Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        DataContext = New DBRepairWizardViewModel(Dispatcher)
    End Sub

    ''' <summary>
    ''' Next Button
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        If LVBackups.SelectedItem IsNot Nothing Then
            Dim backup As BackUpModel = LVBackups.SelectedItem
            Dim backupmanager As New BackupAndRestore(System.AppDomain.CurrentDomain.BaseDirectory() + "Firma")
            If IO.File.Exists(backup.Path) Then
                Dim path As String = backup.Path
                Dim t1 As New Thread(Sub()
                                         backupmanager.Wiederherstellen(path)
                                     End Sub)
                t1.Start()
                t1.Join()
                DialogResult = True
                Me.Close()
            Else
                MessageBox.Show("Datei nicht mehr vorhanden. Bitte wählen sie eine Andere!", "Andere Datei wählen", MessageBoxButton.OK, MessageBoxImage.Error)
                Exit Sub
            End If
        End If
    End Sub

    Private Sub Window_Closed(sender As System.Object, e As System.EventArgs) Handles MyBase.Closed
        If DialogResult = False Then
            Application.Current.Shutdown()
        End If
    End Sub
End Class
